package com.manopservice.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.manopservice.model.CarAutoPartHandType;;


@Repository("carAutoPartHandTypeDAO")
public class CarAutoPartHandTypeDAOImpl implements CarAutoPartHandTypeDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void save(CarAutoPartHandType carAutoPartHandType) {
		sessionFactory.getCurrentSession().saveOrUpdate(carAutoPartHandType);
		
	}

	@Override
	public void delete(int id) {
		CarAutoPartHandType carAutoPartHandType = (CarAutoPartHandType) sessionFactory.getCurrentSession().get(CarAutoPartHandType.class, id);
		sessionFactory.getCurrentSession().delete(carAutoPartHandType);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarAutoPartHandType> findAll() {
		
		return (List<CarAutoPartHandType>) sessionFactory.getCurrentSession().createCriteria(CarAutoPartHandType.class).list();
	}

	@Override
	public CarAutoPartHandType findById(int id) {

		return (CarAutoPartHandType) sessionFactory.getCurrentSession().get(CarAutoPartHandType.class, id);
	}

}
